<!--
 * 医生信息
 *
-->
<template>
    <div style="width: 100%;margin-top: -10px">
        <el-card shadow="hover" :model="modifyForm" :rules="rules" ref="modifyForm">
          <h1>个人信息</h1>
            <table style="margin-left: auto;margin-right: auto">
                <tr>
                    <td>账号 </td>
                    <td>姓名 </td>
                   <td>性别</td>
                </tr>
                <tr>
                  <td>
                    <el-input  v-model="doctorData.dId"></el-input>
                  </td>
                    <td>
                      <el-input  v-model="doctorData.dName"></el-input>
                    </td>
                  <td>
                    <el-input v-model="doctorData.dGender"></el-input>
                  </td>
                </tr>
                <tr>
                    <td>手机号</td>
                  <td>身份证号</td>
                  <td>Email</td>
                </tr>
                <tr>
                    <td>
                        <el-input
                            v-model="doctorData.dPhone"
                        ></el-input>
                    </td>
                  <td>
                    <el-input
                        v-model="doctorData.dCard"
                    ></el-input></td>
                  <td>
                    <el-input
                        v-model="doctorData.dEmail"
                    ></el-input>
                  </td>
                </tr>
                <tr>
                    <td>职位</td>
                    <td>主治</td>
                  <td>年龄</td>
                </tr>
                <tr>
                    <td><el-input
                        v-model="doctorData.dPost"
                    ></el-input></td>
                    <td>
                        <el-input
                            v-model="doctorData.dSection"
                        ></el-input>
                    </td>
                  <td><el-input
                      v-model="doctorData.dAge"
                  ></el-input></td>
                </tr>
                <tr>
                  <td>擅长领域</td>
                  <td>工作经历</td>
                    <td>教育经历</td>
                </tr>
                <tr>
                  <el-input
                      v-model="doctorData.dTalent"
                  ></el-input>
                  <td><el-input type="textarea"
                      v-model="doctorData.dWork"
                  ></el-input></td>
                    <td>
                        <el-input type="textarea"
                            v-model="doctorData.dEducation"
                        ></el-input>
                    </td>
                </tr>
                <tr style="margin-left: auto">
                  <td></td>
                  <td></td>
                  <td>
<!--                  <el-button-->
<!--                    style="font-size: 14px"-->
<!--                    type="success"-->
<!--                    @click="modifyDoctor('modifyForm')">保存</el-button>-->
                  </td>
                </tr>
            </table>
        </el-card>
    </div>
</template>
<script>
import jwtDecode from "jwt-decode";
import { getToken } from "@/utils/storage.js";
import request from "@/utils/request.js";
export default {
    name: "DoctorCard",
    data() {
      //校验手机方法
      var validateMoblie = (rule, value, callback) => {
        if (value === undefined) {
          callback(new Error("请输入手机号"));
        } else {
          let reg =
              /^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8]|8[0-9]|9[1,8,9])\d{8}$/;
          if (!reg.test(value)) {
            callback(new Error("请输入合法的手机号"));
          }
          callback();
        }
      };
      //校验身份证方法
      var validateCard = (rule, value, callback) => {
        if (value === undefined) {
          callback(new Error("请输入身份证号"));
        } else {
          let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
          if (!reg.test(value)) {
            callback(new Error("请输入合法的身份证号码"));
          }
          callback();
        }
      };
        return {
            userId: "",
            doctorData: {},
          modifyForm: {},
          rules: {
            dId: [
              { required: true, message: "请输入账号", trigger: "blur" },
              {
                type: "number",
                message: "账号必须数字类型",
                trigger: "blur",
              },
            ],
            dName: [
              { required: true, message: "请输入姓名", trigger: "blur" },
              {
                min: 2,
                max: 5,
                message: "账号必须是2到5个字符",
                trigger: "blur",
              },
            ],
            dPost: [
              { required: true, message: "请选择职位", trigger: "blur" },
            ],
            dSection: [
              {
                required: true,
                message: "请选择所属科室",
                trigger: "blur",
              },
            ],
            dEmail: [
              { required: true, message: "请输入邮箱", trigger: "blur" },
              {
                type: "email",
                message: "请输入正确的邮箱地址",
                trigger: ["blur", "change"],
              },
            ],
            dPrice: [
              {
                required: true,
                message: "请输入挂号费",
                trigger: "blur",
              },
            ],
            dPhone: [{ validator: validateMoblie }],
            dCard: [{ validator: validateCard }],
            dIntroduction: [
              {
                required: true,
                message: "请输入您的个人简介",
                trigger: "blur",
              },
            ],
          },
        };
    },
    methods: {
      //点击修改医生信息
      modifyDoctor(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            // if (true) {
            request
                .get("admin/modifyDoctor", {
                  params: {
                    dId: this.modifyForm.dId,
                    dGender: this.modifyForm.dGender,
                    dName: this.modifyForm.dName,
                    dPost: this.modifyForm.dPost,
                    dSection: this.modifyForm.dSection,
                    dPhone: this.modifyForm.dPhone,
                    dEmail: this.modifyForm.dEmail,
                    dCard: this.modifyForm.dCard,
                    dPrice: this.modifyForm.dPrice,
                    dIntroduction: this.modifyForm.dIntroduction,
                    dBirthday:this.modifyForm.dBirthday,
                    dAge:this.modifyForm.dAge,
                    dSalary:this.modifyForm.dSalary,
                    dEducation:this.modifyForm.dEducation,
                    dWork:this.modifyForm.dWork,
                    dTalent:this.modifyForm.dTalent
                  },
                })
                .then((res) => {
                  if (res.data.status !== 200)
                    return this.$message.error("修改信息失败！");
                  this.modifyFormVisible = false;
                  this.search();
                  this.$message.success("修改医生信息成功！");
                });
          } else {
            return false;
          }
        });
      },
        //请求医生信息
        requestDoctor() {
          console.log(this.userId);
            request
                .get("admin/findDoctor", {
                    params: {
                        dId: this.userId,
                    },
                })
                .then((res) => {
                    if (res.data.status != 200)
                        return this.$message.error("获取数据失败");
                    this.doctorData = res.data.data;
                });
        },
        //token解码
        tokenDecode(token) {
            if (token !== null) return jwtDecode(token);
        },
    },
    created() {
        //解码token信息
        this.userId = this.tokenDecode(getToken()).dId;
        this.requestDoctor();
    },
};
</script>
<style lang="scss" scope>
td, th {
  white-space: nowrap;
  padding: 10px;
}
</style>
